package com.wangqinlei.cowims126.service.impl;

import com.wangqinlei.cowims126.mapper.CowMapper;
import com.wangqinlei.cowims126.pojo.Cow;
import com.wangqinlei.cowims126.service.CowService;
import com.wangqinlei.cowims126.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author 王勤磊
 */
@Service
public class CowServiceImpl implements CowService {

    @Autowired
    private CowMapper cowMapper;

    @Override
    public PageBean<Cow> queryPage(Map<String, Object> paramMap) {
        PageBean<Cow> pageBean = new PageBean<>((Integer) paramMap.get("pageno"),(Integer) paramMap.get("pagesize"));

        Integer startIndex = pageBean.getStartIndex();
        paramMap.put("startIndex",startIndex);
        List<Cow> datas = cowMapper.queryList(paramMap);
        pageBean.setDatas(datas);

        Integer totalsize = cowMapper.queryCount(paramMap);
        pageBean.setTotalsize(totalsize);
        return pageBean;
    }

    @Override
    public int deleteCow(List<Integer> ids) {
        return cowMapper.deleteCow(ids);
    }

    @Override
    public int addCow(Cow cow) {
        return cowMapper.addCow(cow);
    }

    @Override
    public Cow findById(Integer sid) {
        return cowMapper.findById(sid);
    }

    @Override
    public int editCow(Cow cow) {
        return cowMapper.editCow(cow);
    }

    @Override
    public Cow findByCow(Cow cow) {
        return cowMapper.findByCow(cow);
    }

    @Override
    public boolean isCowByCategoryId(Integer id) {
        List<Cow> cowList = cowMapper.isCowByCategoryId(id);
        if (cowList.isEmpty()){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public int findBySn(String sn) {
        return cowMapper.findBySn(sn);
    }
}
